<?php

namespace app\backstage\validate;

use think\Validate;

class BannerValidate extends Validate
{
    protected $rule = [
        'agent_id' => 'require',
        'type' => 'require|array',
        'table_novel_id1' => 'array',
        'pic1' => 'array',
        'table_novel_id2' => 'array',
        'pic2' => 'array',
        'table_novel_id3' => 'array',
        'pic3' => 'array',
        'table_novel_id4' => 'array',
        'pic4' => 'array',
    ];

    protected $message = [
        'agent_id.require' => '请选择代理商',
        'type.require' => '请选择人群类型',
    ];

    protected $scene = [
        'plAddNovel' => ['agent_id', 'type', 'table_novel_id1', 'pic1', 'table_novel_id2', 'pic2', 'table_novel_id3', 'pic3', 'table_novel_id4', 'pic4'],
    ];

    // 自定义验证规则
    protected function checkIds($value, $rule, $data = [])
    {
        if (!preg_match('#^[1-9][0-9]*(,[1-9][0-9]*)*$#', $value)) {
            return '参数异常，请检查是否为正确的id，并且格式是否正确';
        }
        return true;
    }
}